syntax = "proto3";

package kuma.mesh.v1alpha1;

option go_package = "github.com/kumahq/kuma/api/mesh/v1alpha1";

import "api/mesh/options.proto";
import "api/mesh/v1alpha1/selector.proto";
import "google/protobuf/duration.proto";
import "kuma-doc/config.proto";

option (doc.config) = {
  type : Policy,
  name : "Timeout",
  file_name : "timeout"
};

message Timeout {

  option (kuma.mesh.resource).name = "TimeoutResource";
  option (kuma.mesh.resource).type = "Timeout";
  option (kuma.mesh.resource).package = "mesh";
  option (kuma.mesh.resource).kds.send_to_zone = true;
  option (kuma.mesh.resource).ws.name = "timeout";
  option (kuma.mesh.resource).allow_to_inspect = true;

  // List of selectors to match dataplanes that are sources of traffic.
  repeated Selector sources = 1 [ (doc.required) = true ];

  // List of selectors to match services that are destinations of traffic.
  repeated Selector destinations = 2 [ (doc.required) = true ];

  message Conf {
    // ConnectTimeout defines time to establish connection
    google.protobuf.Duration connect_timeout = 1;

    // Tcp defines timeouts that are applied when the protocol is TCP
    message Tcp {
      // IdleTimeout is defined as the period in which there are no bytes sent
      // or received on either the upstream or downstream connection
      google.protobuf.Duration idle_timeout = 1 [ (doc.required) = true ];
    }
    Tcp tcp = 2;

    // Http defines timeouts that are applied when the protocol is HTTP
    message Http {
      // RequestTimeout is a span between the point at which the entire
      // downstream request (i.e. end-of-stream) has been processed and when the
      // upstream response has been completely processed
      google.protobuf.Duration request_timeout = 1;
      // IdleTimeout is the time at which a downstream or upstream connection
      // will be terminated if there are no active streams
      google.protobuf.Duration idle_timeout = 2;
      // StreamIdleTimeout is the amount of time that the connection manager
      // will allow a stream to exist with no upstream or downstream activity
      google.protobuf.Duration stream_idle_timeout = 3;
      // MaxStreamDuration is the maximum time that a stream’s lifetime will
      // span
      google.protobuf.Duration max_stream_duration = 4;
    }
    Http http = 3;

    // Grpc defines timeouts that are applied when the protocol is GRPC
    message Grpc {
      // StreamIdleTimeout is the amount of time that the connection manager
      // will allow a stream to exist with no upstream or downstream activity
      // Deprecated: use Http.StreamIdleTimeout instead
      google.protobuf.Duration stream_idle_timeout = 1;
      // MaxStreamDuration is the maximum time that a stream’s lifetime will
      // span
      // Deprecated: use Http.MaxStreamDuration instead
      google.protobuf.Duration max_stream_duration = 2;
    }
    // Deprecated: set parameters through Http section
    Grpc grpc = 4;
  }
  Conf conf = 3 [ (doc.required) = true ];
}
